package com.yuexunit.account.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.yuexunit.account.action.v2.model.Account;
import com.yuexunit.constant.GenderEnum;
import com.yuexunit.persist.annotation.Cacheable;
import com.yuexunit.util.DateUtil;


/**
 * 帐号密码 
 * @author wangjinshui
 */
@Entity
@Table(name="AC_ACCOUNT")
@Cacheable(maxCount=5000, timeToIdleSeconds=36000)
public class AccountEntity {
	@Id
	@GeneratedValue
	@Column(name="ACCOUNT_ID")
	private Long accountId;

	@Column(name="FULL_NAME")
	private String fullName;

	@Column(name="ID_CARD_NO")
	private String idCardNo;
	
	@Column(name="MOBILE")
	private String mobile;

	@Column(name="EMAIL")
	private String email;

	@Column(name="GENDER")
	@Enumerated(EnumType.ORDINAL)
	private GenderEnum gender;

	@Column(name="BIRTHDAY")
	private Date birthday;
	
	@Column(name="PIC_UUID")
	private String pictureUuid;

	@Column(name="CREATE_DT")
	private Date createDate;

	private transient Integer appRoleType;
	
	
	public Long getAccountId() {
		return accountId;
	}

	public void setAccountId(Long accountId) {
		this.accountId = accountId;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getIdCardNo() {
		return idCardNo;
	}

	public void setIdCardNo(String idCardNo) {
		this.idCardNo = idCardNo;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public GenderEnum getGender() {
		return gender;
	}

	public void setGender(GenderEnum gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getPictureUuid() {
		return pictureUuid;
	}

	public void setPictureUuid(String pictureUuid) {
		this.pictureUuid = pictureUuid;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	public Integer getAppRoleType() {
		return appRoleType;
	}

	public void setAppRoleType(Integer appRoleType) {
		this.appRoleType = appRoleType;
	}

	public void initCreateDate() {
		setCreateDate(DateUtil.now());
	}

	
	/**
	 * @return spi的帐号信息
	 */
	public Account toAccount() {
		Account account = new Account();
		
		account.setAccountId(accountId);
		account.setFullName(fullName);
		account.setIdCardNo(idCardNo);
		account.setMobile(mobile);
		account.setEmail(email);
		account.setGender(gender == null ? 0 : gender.ordinal());
		account.setBirthday(DateUtil.formatDate(birthday));
		account.setPictureUuid(pictureUuid);
		account.setAppRoleType(appRoleType);
		
		return account;
	}
	
	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		result.append(getClass().getName())
			.append(": accountId=").append(accountId)
			.append(", fullName='").append(fullName).append("'")
			.append(", idCardNo='").append(idCardNo).append("'")
			.append(", mobile='").append(mobile).append("'")
			.append(", email='").append(email).append("'")
			.append(", gender=").append(gender)
			.append(", birthday=").append(birthday)
			.append(", pictureUuid='").append(pictureUuid).append("'")
			.append(", createDate=").append(createDate)
			.append(", appRoleType=").append(appRoleType)
			;
		
		return result.toString();
	}
}
